<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/4/9
 * Time: 下午4:26
 */

namespace Biz\module\Classes\adm;

use Biz\model\ShopBasicInfo as mShopBasicInfo;
use Biz\model\trade\Order as mOrder;
use Biz\model\trade\OrderGoods as mOrderGoods;
use Biz\model\trade\OrderOperateLog as mOrderOperateLog;
use Biz\model\trade\OrderRefund as mOrderRefund;
use Biz\service\Event;
use Biz\service\TradeMsg as sTradeMsg;
use Biz\tools\Amount;
use Doraemon\model\Member as mMember;
use Doraemon\service\User as sUser;
use Biz\validate\trade\OrderRefund as vOrderRefund;
use Biz\model\trade\ShopAddress as mShopAddress;
use Biz\service\trade\ShopAddress as sShopAddress;
use Doraemon\tools\Log as tLog;
use Biz\service\trade\Pay;
use Biz\module\Classes\OrderGoods as clsOrderGoods;



class OrderRefund extends \Biz\module\Classes\OrderRefund
{
    public function rightsInto($adminUid, $refundOrderNo)
    {
        $nowTime = time();

        //查询退款单信息
        $orderSku = self::getRefundOrderInfo($refundOrderNo);

        //判断是否可以介入
        if ($orderSku['refund_info']['status'] != mOrderRefund::STATUS_REJECT) {
            throw new \Exception('该维权不可介入');
        }

        if ($orderSku['refund_info']['rights_status'] != mOrderRefund::RIGHTS_STATUS_NORMAL) {
            throw new \Exception('该维权不可介入');
        }

        //操作退款记录表
        $upData = [
            'rights_into_time' => date('Y-m-d H:i:s', $nowTime),
            'submit_proof_stop_time' => date('Y-m-d H:i:s', $nowTime + mOrderRefund::SUBMIT_PROOF_STOP_TIME),
            'rights_status' => mOrderRefund::RIGHTS_STATUS_PROOFING
        ];

        $result = mOrderRefund::update($upData, ['refund_order_no' => $refundOrderNo]);

        //加日志
        tLog::refund_rights_info('管理员维权介入', ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,
            'params' => ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo],
            'up_data'=>$upData
        ]);

        if ($result->rowCount() == 0) {
            throw new \Exception('操作异常');
        }


        //增加操作日志
        $result = mOrderOperateLog::createLog($orderSku['shop_id'], $orderSku['order_no'], mOrderOperateLog::TRADE_TYPE_ORDER_RIGHTS, [
            'operate_type' => mOrderOperateLog::OPERATE_TYPE_RIGHTS_INTERVENE,
            'operate_user_type' => mOrderOperateLog::OPERATE_USERTYPE_SYS,
            'operate_uid' => $adminUid,
        ], $refundOrderNo, '好好住平台已介入处理，请双方提交凭证，平台将在介入72小时后判定责任归属', '', $upData);

        if ($result->rowCount() == 0) {
            throw new \Exception('维权介入错误');
        }


        //管理员成功接入维权
        Event::push(Event::ORDER_REFUND_RIGHTS_ADM_INTO_SUCCESS, [
            'order_no' => $orderSku['order_no'],
            'refund_order_no' => $refundOrderNo,
            'goods_id' => $orderSku['goods_id'],
            'sku_id' => $orderSku['sku_id'],
            'admin_uid' => $adminUid,
            'rights_into_time'=>$upData['rights_into_time'],
            'uniq_idx' => ['refund_order_no','event_tag','rights_into_time']
        ]);

        if(!in_array($orderSku['order_info']['from_source'],[mOrder::FROM_SOURCE_PARAGRAPH_MINIPROGRAM])) {

            try {
                //给买家发送下行消息
                sTradeMsg::addMsg(401, $orderSku['refund_info']['uid'], [
                    'refund_order_no' => $refundOrderNo,
                    'img' => $orderSku['cover_img_thumb_url'],
                ]);
            }catch (\Exception $e){

            }
        }
    }


    public function rightsJudge($adminUid, $refundOrderNo, $data)
    {
        $nowTime = time();

        //判断表单是否正确
        if (!vOrderRefund::validate($data, 'rightsJudge')) {
            $msg = vOrderRefund::firstError();
            throw new \Exception($msg);
        }
        //查询退款单信息
        $orderSku = self::getRefundOrderInfo($refundOrderNo);


        if ($orderSku['refund_info']['rights_status'] != mOrderRefund::RIGHTS_STATUS_PROOFING) {
            throw new \Exception('不可判定该维权');
        }

        $upData = [
            'rights_judge_result' => $data['judge_result'],
            'rights_process_method' => $data['process_method'],
            'rights_judge_remark' => $data['judge_remark'],
            'rights_judge_images_content' => $data['images_content'],
            'rights_judge_adminuid' => $adminUid,
            'rights_judge_time' => date('Y-m-d H:i:s'),
            'rights_status' => mOrderRefund::RIGHTS_STATUS_JUDGE
        ];



        if ($data['process_method'] != mOrderRefund::RIGHTS_PROCESS_METHOD_NO_REFUND) {

            if ($data['refund_amount'] <= 0) {
                throw new \Exception('请提交退款金额');
            }

            if ($data['refund_amount'] > $orderSku['refund_info']['refund_amount']) {
                throw new \Exception('请正确提交退款金额');
            }

            $canRefund = self::getSkuCanRefundAmount($orderSku, $data['refund_amount'],$orderSku['refund_info']['reason']);

            if ($canRefund['refund_rmb_total'] == 0) {
                throw new \Exception('可退金额出现异常，请正确输入');
            }

            $upData['rights_judge_refund_amount'] = $canRefund['refund_apply_amount'];
            $upData['rights_judge_refund_integral'] = $canRefund['refund_integral'];
            $upData['rights_judge_refund_integral_amount'] = $canRefund['refund_integral_amount'];
            $upData['rights_judge_refund_packet_amount'] = $canRefund['refund_packet_amount'];
            $upData['rights_judge_refund_coupon_amount'] = $canRefund['refund_coupon_amount'];
            $upData['rights_judge_refund_activity_allowance'] = $canRefund['refund_activity_allowance'];
            $upData['rights_judge_refund_rmb'] = $canRefund['refund_sku_pay_amount'];

            $upData['refund_amount'] = $canRefund['refund_apply_amount'];
            $upData['refund_rmb'] = $canRefund['refund_sku_pay_amount'];
            $upData['refund_integral'] = $canRefund['refund_integral'];
            $upData['refund_integral_amount'] = $canRefund['refund_integral_amount'];
            $upData['refund_packet_amount'] = $canRefund['refund_packet_amount'];
            $upData['refund_shipping_amount'] = $canRefund['refund_shipping_fee'];
            $upData['refund_commission_amount'] = $canRefund['refund_commission_amount'];


            if($data['process_method'] == mOrderRefund::RIGHTS_PROCESS_METHOD_REFUND_AMOUNT){
                $shipStatus = clsOrderGoods::checkSkuIsDeliveryIncludePartShip($orderSku['order_no'],$orderSku['sku_id'],$orderSku['order_info']);
                if($shipStatus == clsOrderGoods::SKU_IS_SHIP){
                    if($data['receipt_status'] > -1 && $data['reason'] > -1){
                        $upData['receipt_status'] = $data['receipt_status'];
                        $upData['reason'] = $data['reason'];
                    }

                }elseif($shipStatus == clsOrderGoods::SKU_IS_NOT_SHIP){
                    if($data['reason'] > -1) {
                        $upData['reason'] = $data['reason'];
                    }
                }
            }elseif($data['process_method'] == mOrderRefund::RIGHTS_PROCESS_METHOD_REFUND_ALL){
                if($data['reason'] > -1) {
                    $upData['reason'] = $data['reason'];
                }
            }

        } else {

            if ($data['refund_amount'] != $orderSku['refund_info']['refund_amount']) {
                throw new \Exception('提交失败');
            }



        }

        //操作退款记录表
        $result = mOrderRefund::update($upData, ['refund_order_no' => $refundOrderNo]);

        //加日志
        tLog::refund_rights_info('管理员维权判定', ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,
            'params' => ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,'data'=>$data],
            'up_data'=>$upData
        ]);

        if ($result->rowCount() == 0) {
            throw new \Exception('操作异常');
        }


        //判定出结果后的处理
        switch ($data['process_method']) {
            case mOrderRefund::RIGHTS_PROCESS_METHOD_NO_REFUND:
                //不退款
                $upAfterData = [
                    'refund_amount' => 0,
                    'refund_rmb' => 0,
                    'refund_integral' => 0,
                    'refund_integral_amount' => 0,
                    'refund_packet_amount' => 0,
                    'refund_coupon_amount'=>0,
                    'refund_activity_allowance'=>0,
                    'refund_commission_amount' => 0,
                    'refund_shipping_amount' => 0,
                    'refund_remark' => '判定不退款',
                    'confirm_time' => date('Y-m-d H:i:s', $nowTime),
                    'status' => mOrderRefund::STATUS_COMPLETE
                ];

                mOrderRefund::update($upAfterData, ['refund_order_no' => $refundOrderNo]);

                self::syncRefundAmountRecord($orderSku['order_no'], $orderSku['sku_id'], [
                    'refund_amount' => 0,
                    'refund_status'=>mOrderGoods::REFUND_STATUS_CAN_NOT_REFUND
                ], [
                    'refund_amount[-]'=>($orderSku['refund_info']['refund_rmb']+$orderSku['refund_info']['refund_shipping_amount']),
                ]);


                break;
            case mOrderRefund::RIGHTS_PROCESS_METHOD_REFUND_AMOUNT:
                mOrderRefund::update(['status' => mOrderRefund::STATUS_REFUNDING], ['refund_order_no' => $refundOrderNo]);

                $queueData = [
                    'is_confirm_receipt' => ($orderSku['order_info']['status'] == mOrder::STATUS_SUCCESS) ? 1 : 0,
                    'refund_integral' => $canRefund['refund_integral'],
                    'refund_integral_amount' => $canRefund['refund_integral_amount'],
                    'refund_packet_amount' => $canRefund['refund_packet_amount'],
                    'refund_coupon_amount'=>$canRefund['refund_coupon_amount'],
                    'refund_activity_allowance'=>$canRefund['refund_activity_allowance'],
                    'refund_rmb' => $canRefund['refund_sku_pay_amount'],
                    'refund_shipping_amount' => $canRefund['refund_shipping_fee'],
                    'refund_commission_amount' => $canRefund['refund_commission_amount'],
                ];


                $queueId = $this->intoQueue($orderSku['refund_info']['uid'], $orderSku['refund_info']['shop_id'], $orderSku['order_no'], $refundOrderNo, $queueData);

                //加日志
                tLog::refund_rights_info('维权判定仅退款，入队到退款队列', ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,
                    'params' => ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,'data'=>$data],
                    'queue_id'=>$queueId,
                    'queue_data'=>$queueData
                ]);

                //结算系统对接
                $orderSku['refund_info'] = array_merge($orderSku['refund_info'], [
                    'refund_rmb' => $canRefund['refund_sku_pay_amount'],
                    'refund_shipping_amount' => $canRefund['refund_shipping_fee'],
                    'refund_integral_amount' => $canRefund['refund_integral_amount'],
                    'refund_packet_amount' => $canRefund['refund_packet_amount'],
                    'refund_coupon_amount' => $canRefund['refund_coupon_amount'],
                    'refund_activity_allowance'=>$canRefund['refund_activity_allowance'],
                    'refund_commission_amount' => $canRefund['refund_commission_amount'],
                ]);

                $this->orderRefundIntoSettlementTransaction($orderSku['refund_info']['shop_id'], $orderSku, $queueId, $nowTime, 0);

                self::syncRefundAmountRecord($orderSku['order_no'], $orderSku['sku_id'], [
                    'refund_amount'=>$canRefund['refund_sku_pay_amount'],
                    'refunded_amount' => $canRefund['refund_sku_pay_amount'],
                    'refund_status'=>mOrderGoods::REFUND_STATUS_CAN_NOT_REFUND
                ], [
                    'refund_amount[-]'=>(($orderSku['refund_info']['refund_rmb']+$orderSku['refund_info']['refund_shipping_amount'])-$canRefund['refund_rmb_total']),
                    'refunded_amount[+]' => $canRefund['refund_rmb_total'],
                    'refunded_shipping_amount[+]'=>$canRefund['refund_shipping_fee']
                ]);

                break;
            case mOrderRefund::RIGHTS_PROCESS_METHOD_REFUND_ALL:

                $upAfterData = [];

                $address = sShopAddress::getDefaultAddressByShopId($orderSku['shop_id']);

                if (empty($address)) {
                    throw new \Exception('请正确填写退货收货地址');
                }

                $upAfterData['consignee_name'] = $address['accept_name'];
                $upAfterData['consignee_phone'] = $address['mobile'];
                $upAfterData['consignee_province'] = $address['province'];
                $upAfterData['consignee_city'] = $address['area'];
                $upAfterData['consignee_address'] = $address['address'];
                $upAfterData['consignee_zipcode'] = $address['zipcode'];
                $upAfterData['consignee_notice'] = $address['remark'];

                $upAfterData['type_refund'] = mOrderRefund::TYPE_REFUND_ALL;


                //商家同意退货后，7天内允许用户填写物流信息
                $upAfterData['allow_fill_logistics_close_time'] = date('Y-m-d H:i:s', $nowTime + mOrderRefund::ALLOW_FILL_LOGISTICS_CLOSE_TIME);

                //商家同意退货后，用户需在指定时间内填写物流信息,否则系统自动取消退货
                $upAfterData['auto_cancel_time'] = date('Y-m-d H:i:s', $nowTime + mOrderRefund::AUTO_CANCEL_TIME_FROM_AGREE_REFUND_GOODS);

                //同意退货的时间
                $upAfterData['agree_time'] = date('Y-m-d H:i:s', $nowTime);

                $upAfterData['status'] = mOrderRefund::STATUS_WAIT_REFUND_GOODS;


                mOrderRefund::update($upAfterData, ['refund_order_no' => $refundOrderNo]);


                //加日志
                tLog::refund_rights_info('维权判定退货退款，开始进入到待退货状态', ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,
                    'params' => ['admin_uid'=>$adminUid,'refund_order_no' => $refundOrderNo,'data'=>$data],
                    'up_after_data'=>$upAfterData
                ]);

                break;
        }


        //管理员成功判定维权
        Event::push(Event::ORDER_REFUND_RIGHTS_ADM_JUDGE_SUCCESS, array_merge([
            'uid' => $orderSku['uid'],
            'order_no' => $orderSku['order_no'],
            'refund_order_no' => $refundOrderNo,
            'goods_id' => $orderSku['goods_id'],
            'sku_id' => $orderSku['sku_id'],
            'type_refund' => $orderSku['refund_info']['type_refund'],
            'judge_result' => $upData['rights_judge_result'],
            'process_method' => $upData['rights_process_method'],
            'judge_remark' => $upData['rights_judge_remark'],
            'images_content' => $upData['rights_judge_images_content'],
            'admin_uid' => $adminUid,
            'rights_judge_time'=>$upData['rights_judge_time'],
            'uniq_idx' => ['refund_order_no','event_tag','rights_judge_time']
        ], isset($canRefund) ? $canRefund : []));


        //操作日志表
        mOrderOperateLog::createLog($orderSku['shop_id'], $orderSku['order_no'], mOrderOperateLog::TRADE_TYPE_ORDER_RIGHTS, [
            'operate_type' => mOrderOperateLog::OPERATE_TYPE_JUDGE_RIGHTS,
            'operate_user_type' => mOrderOperateLog::OPERATE_USERTYPE_SYS,
            'operate_uid' => $adminUid,
        ], $refundOrderNo, vsprintf('判定维权。结果：%s 处理方式：%s 说明：%s', [
            mOrderRefund::$rightsJudgeResultDesc[$upData['rights_judge_result']],
            $upData['rights_process_method'] != mOrderRefund::RIGHTS_PROCESS_METHOD_NO_REFUND ? (mOrderRefund::$rightsProcessMethodDesc[$upData['rights_process_method']] . ' ' . $upData['refund_amount'] . '元') : '不退款',
            $upData['rights_judge_remark']
        ]), $upData['rights_judge_images_content'], !empty($upAfterData) ? array_merge($upData, $upAfterData) : $upData);

        if(!in_array($orderSku['order_info']['from_source'],[mOrder::FROM_SOURCE_PARAGRAPH_MINIPROGRAM])) {
            try {
                //给买家下发系统通知
                sTradeMsg::addMsg(402, $orderSku['refund_info']['uid'], [
                    'refund_order_no' => $refundOrderNo,
                    'img' => $orderSku['cover_img_thumb_url'],
                ]);
            }catch (\Exception $e){

            }
        }


        return true;
    }

    public function fetchDetail($refundOrderNo)
    {
        $data = [];
        if (empty($refundOrderNo)) {
            throw new \Exception('退款单号不能为空');
        }

        $refundInfo = mOrderRefund::getRefundOrderInfo($refundOrderNo, 'adm');

        if (empty($refundInfo)) {
            throw new \Exception('退款数据不存在');
        }

        $data['refund_order_no'] = $refundOrderNo;
        $data['order_no'] = $refundInfo['order_no'];

        $data['uid'] = $refundInfo['uid'];

        if ($data['uid'] > 0) {
            $data['user_info'] = mMember::getUserInfo($data['uid']);
        }
        $data['shop_id'] = $refundInfo['shop_id'];

        if ($data['shop_id']) {
            $data['shop_info'] = mShopBasicInfo::getInfo($data['shop_id']);
        }
        $data['sku_id'] = $refundInfo['sku_id'];
        $data['sku_info'] = [
            'title' => $refundInfo['title'],
            'cover_img' => $refundInfo['cover_img_thumb_url'],
            'cover_img_big' => $refundInfo['cover_img_url'],
            'sku_desc' => $refundInfo['sku_desc']
        ];

        $data['refund_amount'] = $refundInfo['refund_amount'];
        $data['refund_integral'] = $refundInfo['refund_integral'];
        $data['refund_rmb'] = $refundInfo['refund_rmb'];
        $data['refund_integral_amount'] = $refundInfo['refund_integral_amount'];
        $data['refund_packet_amount'] = $refundInfo['refund_packet_amount'];
        $data['refund_coupon_amount'] = $refundInfo['refund_coupon_amount'];
        $data['refund_activity_allowance']=$refundInfo['refund_activity_allowance'];
        $data['refund_shipping_amount'] = $refundInfo['refund_shipping_amount'];
        $data['type_refund'] = $refundInfo['type_refund'];
        $data['type_refund_desc'] = $refundInfo['type_refund_desc'];
        $data['reason'] = $refundInfo['reason'];
        $data['reason_desc'] = $refundInfo['reason_desc'];
        $data['status'] = $refundInfo['status'];
        $data['status_desc'] = $refundInfo['status_desc'];
        $data['refund_remark'] = $refundInfo['refund_remark'];
        $data['refund_images_content_url'] = $refundInfo['refund_images_content_url'];
        $data['reject_remark'] = $refundInfo['reject_remark'];
        $data['reject_images_content_url'] = $refundInfo['reject_images_content_url'];
        $data['rights_remark'] = $refundInfo['rights_remark'];
        $data['rights_images_content_url'] = $refundInfo['rights_images_content_url'];
        $data['rights_judge_remark'] = $refundInfo['rights_judge_remark'];
        $data['rights_judge_images_content_url'] = $refundInfo['rights_judge_images_content_url'];
        $data['receipt_status'] = $refundInfo['receipt_status'];
        $data['receipt_status_desc'] = $refundInfo['receipt_status_desc'];

        //判定结果
        $data['rights_judge_result'] = $refundInfo['rights_judge_result'];
        $data['rights_judge_result_desc'] = $refundInfo['rights_judge_result_desc'];
        $data['rights_process_method'] = $refundInfo['rights_process_method'];
        $data['rights_process_method_desc'] = $refundInfo['rights_process_method_desc'];
        $data['rights_judge_remark'] = $refundInfo['rights_judge_remark'];
        $data['rights_judge_images_content'] = $refundInfo['rights_judge_images_content'];
        $data['rights_judge_images_content_url'] = $refundInfo['rights_judge_images_content_url'];
        $data['rights_judge_time'] = $refundInfo['rights_judge_time'];


        $data['rights_status'] = $refundInfo['rights_status'];
        $data['rights_status_desc'] = $refundInfo['rights_status_desc'];
        $data['address_info'] = [
            'accept_name' => $refundInfo['consignee_name'],
            'mobile' => $refundInfo['consignee_phone'],
            'address' => $refundInfo['consignee_address']
        ];
        return $data;
    }

    public function getLogList($refundOrderNo)
    {
        $list = [];
        $logList = mOrderOperateLog::getLogList(['refund_order_no' => $refundOrderNo, 'trade_type' => mOrderOperateLog::TRADE_TYPE_ORDER_REFUND, 'ORDER' => ['addtime' => 'DESC']]);

        $uids = array_filter(array_column($logList, 'operate_uid'), function ($v) {
            if ($v != 0) {
                return true;
            }
            return false;
        });

        $userInfos = sUser::getUsers($uids);

        $sysUserInfo = sUser::getSysUserInfo();

        array_walk($logList, function ($v, $k) use (&$list, $userInfos, $sysUserInfo) {
            $list[$k]['add_time'] = $v['addtime'];
            $list[$k]['text_content'] = $v['text_content'];
            $list[$k]['images_content'] = $v['images_content_url'];
            $list[$k]['user_info'] = [
                'user_type' => $v['operate_user_type'],
                'user_type_desc' => mOrderOperateLog::$operateUserTypeDesc[$v['operate_user_type']],
                'uid' => $v['operate_uid'],
                'name' => $v['operate_user_type'] == mOrderOperateLog::OPERATE_USERTYPE_SYS ? $sysUserInfo['nick'] : (isset($userInfos[$v['operate_uid']])?$userInfos[$v['operate_uid']]['nick']:''),
                'avatar_small' => $v['operate_user_type'] == mOrderOperateLog::OPERATE_USERTYPE_SYS ? $sysUserInfo['avatar_small'] : (isset($userInfos[$v['operate_uid']])?$userInfos[$v['operate_uid']]['avatar_small']:'')
            ];
        });
        return $list;
    }

    public function getRightsLogList($refundOrderNo)
    {
        $list = [];
        $logList = mOrderOperateLog::getLogList(['refund_order_no' => $refundOrderNo, 'trade_type' => mOrderOperateLog::TRADE_TYPE_ORDER_RIGHTS, 'ORDER' => ['addtime' => 'DESC']]);

        $uids = array_filter(array_column($logList, 'operate_uid'), function ($v) {
            if ($v != 0) {
                return true;
            }
            return false;
        });
        $userInfos = sUser::getUsers($uids);

        $sysUserInfo = sUser::getSysUserInfo();

        array_walk($logList, function ($v, $k) use (&$list, $userInfos, $sysUserInfo) {
            $list[$k]['add_time'] = $v['addtime'];
            $list[$k]['text_content'] = $v['text_content'];
            $list[$k]['images_content'] = $v['images_content_url'];
            $list[$k]['user_info'] = [
                'user_type' => $v['operate_user_type'],
                'user_type_desc' => mOrderOperateLog::$operateUserTypeDesc[$v['operate_user_type']],
                'uid' => $v['operate_uid'],
                'name' => $v['operate_user_type'] == mOrderOperateLog::OPERATE_USERTYPE_SYS ? $sysUserInfo['nick'] : $userInfos[$v['operate_uid']]['nick'],
                'avatar_small' => $v['operate_user_type'] == mOrderOperateLog::OPERATE_USERTYPE_SYS ? $sysUserInfo['avatar_small'] : $userInfos[$v['operate_uid']]['avatar_small']
            ];
        });
        return $list;
    }

    public function calRefundAmount($refundOrderNo, $refundAmount = null)
    {

        $data = [];

        $orderSku = self::getRefundOrderInfo($refundOrderNo, false);

        $data = self::getSkuCanRefundAmount($orderSku, $refundAmount,$orderSku['refund_info']['reason']);

        $data['shop_deduct_total'] = Amount::format($data['refund_apply_amount']+$data['refund_integral_amount']+$data['refund_packet_amount']+$data['refund_coupon_amount']+$data['refund_activity_allowance']);

        $data['refund_hhz_total'] = Amount::format($data['refund_integral_amount']+$data['refund_packet_amount']+$data['refund_coupon_amount']+$data['refund_activity_allowance']);


        return $data;
    }


}